<!DOCTYPE HTML>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="gray-bg">
    
     <div class="container-div">
		<div class="row">
			<div class="col-sm-12 search-collapse">
				<form id="formId">
					<input name="deptId"  style="display: none;" id="treeId"/>
					<div class="select-list">
						<ul>
							<li>
								名称：<input type="text" name="name"/>
							</li>

							<li>
								供电企业：<input  type="text" name="deptName" onclick="selectDeptTree()" readonly="true" id="treeName">
							</li>

							<li>
								电费类别：<select id="userType" name="userType"  th:with="type=${@dict.getType('user_type')}">
									<option th:text="全部" value=""></option>
									<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
									<!--<option th:text="直购电" value="直购电"></option>-->
									<!--<option th:text="自备电厂" value="自备电厂"></option>-->
									<!--<option th:text="富余电量" value="富余电量"></option>-->
									<!--<option th:text="电能替代" value="电能替代"></option>-->
								</select>
							</li>

							<li>
								上网结构：<select id="upStructure" name="upStructure"  th:with="type=${@dict.getType('up_structure')}">
								<option th:text="全部" value=""></option>
								<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
							</select>
							</li>

							<li>
								电压等级：<select id="voltageGrade" name="voltageGrade"  th:with="type=${@dict.getType('voltage_grade')}">
								<option th:text="全部" value=""></option>
								<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
							</select>
							</li>

							<li>
								用电类别：<select id="useEleType" name="useEleType"  th:with="type=${@dict.getType('use_ele_type')}">
									<option th:text="全部" value=""></option>
									<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
								</select>
							</li>

							<li>
								用电替代方案：<select id="useEleChangeType" name="useEleChangeType"  th:with="type=${@dict.getType('use_ele_change_type')}">
								<option th:text="全部" value=""></option>
								<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
							</select>
							</li>

							<li>
								<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
								<a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
							</li>
						</ul>
					</div>
				</form>
			</div>
			
	        <div class="btn-group-sm hidden-xs" id="toolbar" role="group">
				<a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="basics:user:add">
					<i class="fa fa-plus"></i> 添加
				</a>
				<a class="btn btn-primary btn-edit disabled" onclick="$.operate.edit()" shiro:hasPermission="basics:user:edit">
					<i class="fa fa-edit"></i> 修改
				</a>
				<a class="btn btn-danger btn-del btn-del disabled" onclick="$.operate.removeAll()" shiro:hasPermission="basics:user:remove">
					<i class="fa fa-remove"></i> 删除
				</a>
				<a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="basics:user:export">
						<i class="fa fa-download"></i> 导出
				 </a>
			</div>
			<div class="col-sm-12 select-table table-striped">
				<table id="bootstrap-table" data-mobile-responsive="true"></table>
			</div>
		</div>
	</div>
    <div th:include="include :: footer"></div>
    <script th:inline="javascript">
        var listFlag = [[${@permission.hasPermi('basics:user:list')}]];
        var editFlag = [[${@permission.hasPermi('basics:user:edit')}]];
        var removeFlag = [[${@permission.hasPermi('basics:user:remove')}]];
        var userTypeDatas = [[${@dict.getType('user_type')}]];
        var upStructureDatas = [[${@dict.getType('up_structure')}]];
        var voltageGradeDatas = [[${@dict.getType('voltage_grade')}]];
        var useEleTypeGradeDatas = [[${@dict.getType('use_ele_type')}]];
        var useEleChangeTypeDatas = [[${@dict.getType('use_ele_change_type')}]];
        var prefix = ctx + "basics/user";
		/*用户管理-新增-选择部门树*/
        function selectDeptTree() {
            var treeId = $("#treeId").val();
            var deptId = $.common.isEmpty(treeId) ? "100" : $("#treeId").val();
            var url = ctx + "system/dept/selectDeptTree/" + deptId;
            var options = {
                title: '选择所属供电企业',
                width: "380",
                url: ctx + "system/dept/selectDeptTree/" + deptId,
                callBack: doSubmit
            };
            $.modal.openOptions(options);
        }
        function doSubmit(index, layero){
            var tree = layero.find("iframe")[0].contentWindow.$._tree;
            if ($.tree.notAllowParents(tree)) {
                var body = layer.getChildFrame('body', index);
                $("#treeId").val(body.find('#treeId').val());
                $("#treeName").val(body.find('#treeName').val());
                layer.close(index);
            }
        }

        var query_dict = null;
		$.post(ctx + "system/dict/data/queryDict" , function (r) {
			query_dict = r;
		});

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
				exportUrl: prefix + "/export",
                modalName: "大用户基础数据",
				search: false,
		        showExport: true,
                columns: [{
		            checkbox: true
		        },
				{
					field : 'id', 
					title : '',
					visible: false
				},
				{
					field : 'userId', 
					title : '操作人ID',
					sortable: false,
                    visible: false
				},
				{
					field : 'dept.deptName',
					title : '供电单位',
					sortable: false
				},
				{
					field : 'userType', 
					title : '电费类别',
					sortable: true,
                    formatter: function(value, row, index) {
                        var queryData = "";
                        var ss = value.replace(/\"/g, "").split(",");
                        var rs = query_dict;
							for (var i = 0; i < ss.length; i++) {
								for (d in rs) {
									if (ss[i] == rs[d].dictValue + "") {
                                        queryData += rs[d].dictLabel + ",";
									}
								}
							}
							if (queryData.length > 0) {
                                queryData = queryData.substring(0, queryData.length - 1);
							}
							return queryData;
//                        return $.table.selectDictLabel(userTypeDatas, value);
                    }
				},
				{
					field : 'name', 
					title : '名称',
					sortable: true
				},
				{
					field : 'upStructure', 
					title : '上网结构',
					sortable: true,
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(upStructureDatas, value);
                    }
				},
				{
					field : 'voltageGrade', 
					title : '电压等级',
					sortable: true,
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(voltageGradeDatas, value);
                    }
				},
				{
					field : 'userNum', 
					title : '用户户号',
					sortable: true
				},
				{
					field : 'useEleType', 
					title : '用电类别',
					sortable: true,
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(useEleTypeGradeDatas, value);
                    }
				},
				{
					field : 'useEleChangeType', 
					title : '用电替代方案类别',
					sortable: true,
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(useEleChangeTypeDatas, value);
                    }
				},
				{
					field : 'address', 
					title : '地址',
					sortable: true
				},
				{
					field : 'addDate', 
					title : '录入时间',
					sortable: true,
                    visible: false
				},
		        {
		            title: '操作',
		            align: 'center',
		            formatter: function(value, row, index) {
		            	var actions = [];
		            	actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="#" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="#" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        actions.push('<a class="btn btn-info btn-xs ' + listFlag + '" href="#" onclick="detail(\'' + row.id + '\')"><i class="fa fa-list-ul"></i>计量点列表</a> ');
                        return actions.join('');
		            }
		        }]
            };
            $.table.init(options);
        });

		/*计量点列表-详细*/
        function detail(dictId) {
            var url = prefix + '/detail/' + dictId;
            createMenuItem(url, "计量点列表");
        }
    </script>
</body>
</html>